﻿#pragma once

#include "common.h"

// 单例模式
class CentralCache
{
public:
	static CentralCache* getInstance()
	{
		static CentralCache m_instance;
		return &m_instance;
	}
	// 从central cache中获取内存
	size_t fetchRangeObj(void*& start, void*& end, size_t batchNum, size_t size);
	// 获取一个非空的span
	Span* getOneSpan(SpanList& list, size_t byte_size);

	// 释放对象时，链表过长时，回收内存回到page cache
	void releaseListToSpans(void* start, size_t byte_size);

private:
	SpanList m_spanLists[NFREELIST];		// 管理多个自由链表桶	

private:
	CentralCache() {}
	CentralCache(const CentralCache&) = delete;
	CentralCache& operator=(const CentralCache&) = delete;
};